const kdup = {};
kdup.config = {};
kdup.mainFieleKey = {barcode:{}, stock:{}, sp:{}, lot:{}, srcType:{}, stockTo:{}, spTo:{}, productDate:{}};
kdup.fentryid=0;
kdup.index = 0;
kdup.formDate1={};
kdup.fid = 0;
kdup.countscheme='';//盘点方案
kdup.userInfo = {userid:0,account:"",username:"",usertoken:""};
kdup.GxData={};
kdup.color=uni.getStorageSync("color");
var d = new Date();
var ye = d.getFullYear();
var mo = (d.getMonth()+1).toString().padStart(2,'0');
var da = d.getDate().toString().padStart(2,'0');
kdup.datetime = ye+'-'+mo+'-'+da;
//为空true 否则false
kdup.isEmpty = function(str, isObj) {
	if (str === null || str === undefined)
		return true;
	if (!isObj && str === "")
		return true;
	if ((str instanceof Array) && str.length == 0)
		return true;
	return false;
};
//json如果property不为空放回json的property的值，否则放回defaultValue
kdup.getJsonVal = function(json, property, defaultValue) {
	if (json == null) return defaultValue;
	if (!json.hasOwnProperty(property)) return defaultValue;
	var value = json[property];
	if (kdup.isEmpty(value)) return defaultValue;
	return value;
};
//json如果property不为空放回property==value的jsonArray对象
kdup.getJson = function(jsonArray, property, value) {
	if (jsonArray == null || jsonArray.length == 0) return null;
	for (var i = 0; i < jsonArray.length; i++) {
		var json = jsonArray[i];
		if (!json.hasOwnProperty(property)) continue;
		var valueTo = kdup.getJsonVal(json, property, "");
		if (valueTo == value) return json;
	}
	return null;
};

kdup.split = function(str, separator) {
	if (kdup.isEmpty(str)) return null;
	return str.split(separator);
};

kdup.join = function(array, separator) {
	if (array == null || array.length == 0) return "";
	return array.join(separator);
};

kdup.endsWith = function(str, otherStr) {
	if (kdup.isEmpty(str) || kdup.isEmpty(otherStr)) return false;
	return str.endsWith(otherStr);
};

kdup.startsWith = function(str, otherStr) {
	if (kdup.isEmpty(str) || kdup.isEmpty(otherStr)) return false;
	return str.startsWith(otherStr);
};

kdup.getTableHead = function(colArray, isCheck) {
	var columnArray = new Array();
	var sumWidth = 0;
	if (isCheck) { //无源单开启多选，有源单关闭多选
		columnArray[columnArray.length] = {
			type: 'checkbox',
			width: 80,
			align: "center",
			key: "checkbox"
		};
		sumWidth += 80;
	}
	columnArray[columnArray.length] = {
		type: 'index',
		width: 70,
		align: "center",
		key: "index"
	};
	sumWidth += 70;
	//公式就字节
	var width = 200, dWidth = 1200;
	uni.getSystemInfo({
		success: function(res) {
			dWidth = res.windowWidth * 2 + 50;
		}
	});
	for (var i = 0; i < colArray.length; i++) {
		var col = colArray[i];
		if (kdup.endsWith(col, "_hide")) continue;
		if (col == "rn") continue;
		if (i == colArray.length - 1) {
			var cWidth = dWidth - sumWidth;
			if (cWidth > 0 && cWidth > width)
				width = cWidth;
		}
		if(kdup.endsWith(col, "id")){
			columnArray[columnArray.length] = {
				title: "内码",
				key: col,
				align: "center",
				width: 200
				
			};
			continue;
		}
		var defaultWidth = 200;
		switch (col) {
			case "扫描状态":
				width = 150;
				columnArray[columnArray.length] = {
					title: "扫描状态",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "name":
			case "fname":
				width = 260;
				columnArray[columnArray.length] = {
					title: "名称",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "number":
			case "fnumber":
				width = 350;
				columnArray[columnArray.length] = {
					title: "编码",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "billno":
			case "单据编号":
				width = 350;
				columnArray[columnArray.length] = {
					title: "单据编号",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fbarcode":
			case "条码":
				width = 500;
				columnArray[columnArray.length] = {
					title: "条码",
					key: col,
					align: "center",
					width: width
				};
				break;
				case "生产订单号":
				case "fmobillno":
					width = 300;
					columnArray[columnArray.length] = {
						title: "生产订单号",
						key: col,
						align: "center",
						width: width
					};
					break;
			case "用料清单号":
				width = 300;
				columnArray[columnArray.length] = {
					title: "用料清单号",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "操作员":
				width = 300;
				columnArray[columnArray.length] = {
					title: "操作员",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "对应生产订单":
				width = 320;
				columnArray[columnArray.length] = {
					title: "对应生产订单",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "汇报时间":
				width = 320;
				columnArray[columnArray.length] = {
					title: "汇报时间",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fmatnumber":
			case "物料编码":
				width = 300;
				columnArray[columnArray.length] = {
					title: "物料编码",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "供应商":
			case "客户":
				width = 400;
				columnArray[columnArray.length] = {
					title: "供应商",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fmatname":
			case "物料名称":
				width = 300;
				columnArray[columnArray.length] = {
					title: "物料名称",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fmatmodel":
			case "fspecification":
			case "fdescription":
				width = 400;
				columnArray[columnArray.length] = {
					title: "规格型号",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fprintqty":
				width = defaultWidth;
				columnArray[columnArray.length] = {
					title: "打印数量",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "finvqty":
			case "invqty":
				width = defaultWidth;
				columnArray[columnArray.length] = {
					title: "库存数量",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "funitname":
			case "单位":
				width=100;
				columnArray[columnArray.length] = {
					title: "单位",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fnote":
				width=300;
				columnArray[columnArray.length] = {
					title: "备注",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fqty":
				width = defaultWidth;
				columnArray[columnArray.length] = {
					title: "数量",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fmustqty":
				width = defaultWidth;
				columnArray[columnArray.length] = {
					title: "应收数量",
					key: col,
					align: "center",
					width: width
				};
				break;
		    case "frealqty":
		    	width = defaultWidth;
		    	columnArray[columnArray.length] = {
		    		title: "实收数量",
		    		key: col,
		    		align: "center",
		    		width: width
		    	};
		    	break;
			case "fstockname":
				width = "240";
				columnArray[columnArray.length] = {
					title: "仓库名称",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "status"://单据状态
				width = "200";
				columnArray[columnArray.length] = {
					title: "单据状态",
					key: col,
					align: "center",
					width: width
				};
				break;
		    case "fworkshopname"://生产车间
			width = "200";
			columnArray[columnArray.length] = {
				title: "生产车间",
				key: col,
				align: "center",
				width: width
			};
			break;
			case "documentstatus"://产品类型
				width = "200";
				columnArray[columnArray.length] = {
					title: "产品类型",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fspname":
				width = defaultWidth;
				columnArray[columnArray.length] = {
					title: "库位名称",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "flot_text":
				width = "240";
				columnArray[columnArray.length] = {
					title: "批号",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "auxpropname":
				width = "240";
				columnArray[columnArray.length] = {
					title: "辅助属性",
					key: col,
					align: "center",
					width: width
				};
				break;	
			case "fauxinvqty":
				width = defaultWidth;
				columnArray[columnArray.length] = {
					title: "辅助数量",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "fseq":
			case "seq":
			case "fmoentryseq":
			case "分录行号":
				width=150;
				columnArray[columnArray.length] = {
					title: "分录行号",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "辅助数量":
				width=1;
				columnArray[columnArray.length] = {
					title: "辅助数量",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "单据类型":
			         width=300;
				columnArray[columnArray.length] = {
					title: "单据类型",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "创建时间":
					 width=320;
				columnArray[columnArray.length] = {
					title: "创建时间",
					key: col,
					align: "center",
					width: width
				};
				break;
			case "单据业务类型":
					 width=320;
				columnArray[columnArray.length] = {
					title: "单据业务类型",
					key: col,
					align: "center",
					width: width
				};
				break;
			default:
				width = defaultWidth;
				columnArray[columnArray.length] = {
					title: col,
					key: col,
					align: "center",
					width: width
				};
				break;
		}
		sumWidth += width;
	}
	if(sumWidth < dWidth){
		for(var i = columnArray.length - 1; i >= 0; i--){
			if(columnArray[i].width < 10) continue;
			columnArray[i].width = dWidth - (sumWidth - columnArray[i].width);
			break;
		}
	}
	
		
	return columnArray;
};
//统一修改json   this当前:that   键this.property.fkey    值this.date    保存值this.formDate[this.index].rules.rowvalue 临时表id this.fid 
kdup.updateValue = function(that, ffieldname, data, rowvalue, fid) {
	//字符串拼接
	var str="";
	//操作员多选
	if(ffieldname!="FCZY"){
		 str = "update top_TerminalData set " + ffieldname + "='" + data + "' where FID=" + fid;
	}else{
		 str = "";//操作员多选
		}
	var data = {
		sql: str,
		key: ffieldname,
		rowvalue: rowvalue,
		fid: fid
	}
	that.$myRequest.postRequest("UpdateFieldValue", data).then(res1 => {
		if (!that.$kdup.isEmpty(res1.data.error)) {
			//未找到数据
			uni.showToast({
				title: res1.data.error,
				icon: "none",
				duration: 3000
			});
		}
	})
}
kdup.getTableContent = function(colArray, data) {
	
	var valueArray = new Array();
	for (var i = 0; i < data.length-1; i++) {
		var obj = data[i],
			json = {};
		for (var j = 0; j < colArray.length; j++) {
			var col = colArray[j];
			if (col.key == "checkbox" || col.key == "index") continue;
			json[col.key] = obj[col.key];
		}
		valueArray[valueArray.length] = json;
	
	}
	return valueArray;
};
//负责找到和当前对象有关联的对象
kdup.getKey = function(colArray, data) {
	if (kdup.isEmpty(data)) return null;
	for (var i = 0; i < colArray.length; i++) {
		if (kdup.isEmpty(colArray[i].key)) continue;
		if (colArray[i].property.fkey == data && colArray[i].property.fuseorgkey != data) {
			return colArray[i]
		}
	}
	return null;
};
//找到和组织有关联的多个对象
kdup.getUnion = function(that, colArray, data, fid) {
	if (kdup.isEmpty(data)) return colArray
	var array = [];
	for (var i = 0; i < colArray.length; i++) {
		if (kdup.isEmpty(colArray[i].key)) continue;
		//修改供应商的时候 忽略源单单号
		if (colArray[i].property.fuseorgkey == data && colArray[i].property.ffieldtype != 13) {
			array.push(colArray[i]);
		}
	}
	//不等于空则清空对象
	if (array.length != 0) {
		for (var i = 0; i < colArray.length; i++) {
			//这里的array.length-1是因为这个条码是表体字段，表头找不到这个列
			for (var j = 0; j < array.length - 1; j++) {
				if (colArray[i].key == array[j].key) {

					//首先设置显示值为空
					colArray[i].rules.value = "";
					colArray[i].rules.rowvalue = {
						id: ""
					};
					//循环清空数据库的值		
					kdup.updateValue(that, colArray[i].property.ffieldname, "", colArray[i].rules.rowvalue, fid);
				}
			}
		}
	}
	return colArray;
};
//字节和宽度之间的转换
kdup.byteConvert = function(bytes) {};
//这里负责找到条码id放回索引值+1
kdup.getindex = function(Array) {
	var index;
	for (var i = 0; i < Array.length; i++) {
		if (Array[i].property.ffieldtype == "6") {
			index = i + 1;
		}
	}
	return index;
}
kdup.getindex1 = function(Array) {
	var index;
	for (var i = 0; i < Array.length; i++) {
		if (Array[i].property.ffieldtype == "59") {
			index = i + 1;
		}
	}
	return index;
}
//添加工序系列对象
kdup.addGxhb=function(array){
	var d = new Date();
	var ye = d.getFullYear();
	var mo = (d.getMonth()+1).toString().padStart(2,'0');
	var da = d.getDate().toString().padStart(2,'0');
	var time = ye+'-'+mo+'-'+da;
	var spObj = kdup.getJson(array, "label", "汇报数量");
    if (spObj == null) {
	array.splice(5,0,
	{
			placeholder: "请输入汇报数量", //提示
			label: "汇报数量", //标题
			type: "number", //类型ffieldtype
			disabled: false, //是否启用
			isshowdel:true,
			maxlength: "-1", //输入长度
			firstFocus:false,
			property: {
				fcloudbillkey:"top_GXHB",
				ffieldtype: 0,
				fishidden: 0,
				ffieldtype:999
			}, //配置属性
			key: "fgxqty", //唯一标识
			rules: {
				flag: 999, //标识
				name: "fgxqty", //名称fkey
				value: "", //显示值
				rowvalue: {id:""},
				verify: "", //必录fmustinput
				errMess: "请输入汇报数量" //非空提示
			}
		}, 
		{
			placeholder: "请输入不合格数", //提示
			label: "不合格数", //标题
			type: "number", //类型ffieldtype
			disabled: false, //是否启用
			isshowdel:true,
			firstFocus:false,
			maxlength: "-1", //输入长度
			property: {
				fcloudbillkey:"top_GXHB",
				fishidden: 0,
				ffieldtype:999
			},
			key: "ffailqty", //唯一标识
			rules: {
				flag: 999, //标识
				name: "ffailqty", //名称fkey
				value: "", //显示值
				rowvalue: {id:""},
				verify: "", //必录fmustinput
				errMess: "请输入不合格数" //非空提示
			}
		}, 
		{
			placeholder: "请输入报废数量", //提示
			label: "报废数量", //标题
			type: "number", //类型ffieldtype
			disabled: false, //是否启用
				isshowdel:true,
			firstFocus:false,
			maxlength: "-1", //输入长度
			property: {
				fcloudbillkey:"top_GXHB",
				fishidden: 0,
				ffieldtype:999
			},
			key: "fbadqty", //唯一标识
			rules: {
				flag: 999, //标识
				name: "fbadqty", //名称fkey
				value: "", //显示值
				rowvalue: {id:""},
				verify: "", //必录fmustinput
				errMess: "请输入报废数量" //非空提示
			}
	}
	)
	}
};

//这里处理碰到条码就添加控件  物料格式，规格，计量单位 写死的
kdup.addControl = function(array,fcloudbillkey) {
	if(fcloudbillkey == "top_GXHB"){
	array.splice(kdup.getindex1(array),0, {
		placeholder: "请输入物料编码", //提示
		label: "物料编码", //标题
		type: "text", //类型ffieldtype
		disabled: true, //是否启用
		maxlength: "-1", //输入长度
		property: {
			fishidden: 0
		},
		key: "", //唯一标识
		rules: {
			flag: 0, //标识
			name: "materialmodel", //名称fkey
			value: "", //显示值
			rowvalue: { //保存值
				id: ""
			},
			verify: "", //必录fmustinput
			errMess: "请输入物料编码" //非空提示
		}
	}, {
		placeholder: "请输入规格", //提示
		label: "规格", //标题
		type: "text", //类型ffieldtype
		disabled: true, //是否启用
		maxlength: "-1", //输入长度
		property: {
			fishidden: 0
		},
		key: "", //唯一标识
		rules: {
			flag: 0, //标识
			name: "spec", //名称fkey
			value: "", //显示值
			rowvalue: { //保存值
				id: ""
			},
			verify: "", //必录fmustinput
			errMess: "请输入物料规格" //非空提示
		}
	}, {
		placeholder: "请输入计量单位", //提示
		label: "计量单位", //标题
		type: "text", //类型ffieldtype
		disabled: true, //是否启用
		maxlength: "-1", //输入长度
		property: {
			fishidden: 0
		},
		key: "", //唯一标识
		rules: {
			flag: 0, //标识
			name: "unit", //名称fkey
			value: "", //显示值
			rowvalue: { //保存值
				id: ""
			},
			verify: "", //必录fmustinput
			errMess: "请输入计量单位" //非空提示
		}
	});	
	}else
	if (array[kdup.getindex(array)].label != "物料编码" ) { //不为空则添加控件
		array.splice(kdup.getindex(array), 0, {
			placeholder: "请输入物料编码", //提示
			label: "物料编码", //标题
			type: "text", //类型ffieldtype
			disabled: true, //是否启用
			maxlength: "-1", //输入长度
			property: {
				fishidden: 0
			},
			key: "", //唯一标识
			rules: {
				flag: 0, //标识
				name: "materialmodel", //名称fkey
				value: "", //显示值
				rowvalue: { //保存值
					id: ""
				},
				verify: "", //必录fmustinput
				errMess: "请输入物料编码" //非空提示
			}
		}, {
			placeholder: "请输入规格", //提示
			label: "规格", //标题
			type: "text", //类型ffieldtype
			disabled: true, //是否启用
			maxlength: "-1", //输入长度
			property: {
				fishidden: 0
			},
			key: "", //唯一标识
			rules: {
				flag: 0, //标识
				name: "spec", //名称fkey
				value: "", //显示值
				rowvalue: { //保存值
					id: ""
				},
				verify: "", //必录fmustinput
				errMess: "请输入物料规格" //非空提示
			}
		}, {
			placeholder: "请输入计量单位", //提示
			label: "计量单位", //标题
			type: "text", //类型ffieldtype
			disabled: true, //是否启用
			maxlength: "-1", //输入长度
			property: {
				fishidden: 0
			},
			key: "", //唯一标识
			rules: {
				flag: 0, //标识
				name: "unit", //名称fkey
				value: "", //显示值
				rowvalue: { //保存值
					id: ""
				},
				verify: "", //必录fmustinput
				errMess: "请输入计量单位" //非空提示
			}
		});
	}
	return array;
};
//碰到对象是否包含条码详情
kdup.getBarcodeDetail = function(array, obj, count, sum, smallbars) {
	//包装条码10，14，20   的时候添加
	var spObj = kdup.getJson(array, "label", "条码详情");
	if (obj.barcodetype == 1) {
		if (spObj == null) {
			array.push( //这里的条码数量和汇总数可以根据后台赋值
				kdup.getObj(count, sum, smallbars)
			)
		}
	} 
	// else {
	// 	if (spObj != null) { //删除数组元素
	// 		for (var i = array.length - 1; i >= 0; i--) {
	// 			if (array[i].label == "条码详情") {
	// 				array.splice(i, 1)
	// 			} else if (array.label == "源单明细") {
	// 				array.splice(i, 1)
	// 			}
	// 		}
	// 	}
	// }
	
	return array;
};
//碰到对象是否包含源单明细
kdup.getSourceDetail = function(array, obj, count, sum, source) {
	var spObj = kdup.getJson(array, "label", "源单明细");
	// if (obj.barcodetype == 1) {
		if (spObj == null) {
			array.push( //这里的条码数量和汇总数可以根据后台赋值
				kdup.getSource(count, sum, source)
			)
		}
	 else {
	spObj.rules.value="源单明细包含" + count + "张源单,总数" + sum; //显示值
	spObj.rules.rowvalue.id=source;
	// 	if (spObj != null) { //删除数组元素
	// 		for (var i = array.length - 1; i >= 0; i--) {
	// 			if (array[i].label == "条码详情") {
	// 				array.splice(i, 1)
	// 			} else if (array.label == "源单明细") {
	// 				array.splice(i, 1)
	// 			}

	// 		}
	 //	}
	 }
	return array;
}

//这里是碰到包装条码生成一个对象
kdup.getObj = function(count, sum, smallbars) {
	return {
		placeholder: "请输入条码详情", //提示
		label: "条码详情", //标题
		type: "text", //类型ffieldtype
		disabled: true, //是否启用
		firstFocus: false, //获得焦点
		maxlength: "-1", //输入长度
		key: "bardetail", //唯一标识
		property: {
			ffieldtype: '500',
			ffieldname: 'bardetail',
			fishidden: '0'
		}, //配置属性
		rules: {
			flag: "500", //标识
			name: "barcode", //名称fkey
			value: "包装条码包含" + count + "个小条码,总数" + sum, //显示值
			rowvalue: { //保存值
				id: smallbars
			},
			verify: "", //必录fmustinput
			errMess: "请输入条码详情" //非空提示
		}
	}
};
//这里是碰到包装条码生成一个对象
kdup.getSource = function(count, sum, Source) {
	return {
		placeholder: "请输入源单明细", //提示
		label: "源单明细", //标题
		type: "text", //类型ffieldtype
		disabled: true, //是否启用
		firstFocus: false, //获得焦点
		maxlength: "-1", //输入长度
		key: "sourceeBillno", //唯一标识
		property: {
			ffieldtype: '501',
			ffieldname: 'sourceeBillno',
			fishidden: '0'
		}, //配置属性
		rules: {
			flag: "501", //标识
			name: "sourceeBillno", //名称fkey
			value: "源单明细包含" + count + "张源单,总数" + sum, //显示值
			rowvalue: { //保存值
				id: Source
			},
			verify: "", //必录fmustinput
			errMess: "请输入源单明细" //非空提示
		}
	}
}
//依次解锁控件
//array[i].property.finorout 是否入库字段  row.isbarcodemgr是否唯一码
//row.fisopenlocation是否启用库位   row.isbatchmgr是否启用批号
//row.iskfperiod是否启用有效期
//仓库：判断是否用唯一码管理，若等于0 不锁定 可选，否则根据 1 2 -2入库(不锁定)    ( 0调拨 -1出库 )出库（锁定）
//库位：断是否启用库位管理，若等于0 锁定，判断是否用唯一码管理，若等于0 不锁定可选，否则根据 1 2 -2入库(不锁定)    ( 0调拨 -1出库 )出库（锁定）
//批号：先判断是否启用批号管理，若等于0 锁定，判断是否用唯一码管理，若等于0 不锁定可选，否则根据 1 2 -2入库(不锁定)    ( 0调拨 -1出库 )出库（锁定）
//生产日期：断是否启用有效期管理，若等于0 锁定，判断是否用唯一码管理，若等于0 不锁定可选，否则根据 1 2 -2入库(不锁定)    ( 0调拨 -1出库 )出库（锁定）
//批号入库输入 出库选择

//条码    //源单
kdup.unLock = function(array, data, smallbars, srcInfos, that) {
	var row=data.Table[0];
	var isedit=data.hasOwnProperty("entryid")?true:false;
	
	var auxProptyInfos = null;
	if(data.hasOwnProperty("auxProptyInfos"))
		auxProptyInfos = data.auxProptyInfos;
	var sum = 0; //如果不为空并且长度大于0则新增条码
	if (smallbars != undefined && smallbars.length > 0) {
		for (var i = 0; i < smallbars.length; i++) {
			sum += parseFloat(smallbars[i].fqty);
		}
		array = kdup.getBarcodeDetail(array, row, smallbars != undefined ? smallbars.length : 0, sum, smallbars);
	}
	var sumqty = 0; //如果不为空并且长度大于0则新增源单
	if (srcInfos != undefined && srcInfos.length > 0) {
		for (var i = 0; i < srcInfos.length; i++) {
			sumqty += parseFloat(srcInfos[i].fqty);
		}
		array = kdup.getSourceDetail(array, row, srcInfos != undefined ? srcInfos.length : 0, sumqty, srcInfos);
	}
	for (var i = 0; i < array.length; i++) {
		if (array[i].key == "" || array[i].key == "bardetail" || array[i].key == "sourceeBillno") 
			continue;
			
		//解锁仓库
		if (array[i].property.ffieldtype == 7) {
			var valueObj = {
				id: 0,
				number: "",
				name: "",
				masterid: 0,
				isopenlocation: 0
			};
			if (row.isbarcodemgr == 1) {
				if (array[i].property.finorout == 1 || array[i].property.finorout == 2 || array[i].property.finorout == -1) {
					array[i].disabled = false; //解锁仓库

				} else {
					array[i].disabled = true; //锁定仓库
				}
			} else {
				array[i].disabled = false; //锁定仓库
			}
			
			//初始化赋值
			 var stockId = kdup.getJsonVal(row, "stockid", 0);
			if(array[i].savelastvalue != null && array[i].property.finorout==1 && array[i].property.fscanposition ==1
				&& !isedit && array[i].property.fisnosavelast!=1) {
			    array[i].rules.value = array[i].savelastvalue.displayVal;
				array[i].rules.rowvalue = array[i].savelastvalue.saveValue;
				}else if (stockId > 0) {
				valueObj.id = stockId;
				valueObj.masterid = kdup.getJsonVal(row, "stockmasterid", 0);
				valueObj.masterid = valueObj.masterid == 0 ? stockId : valueObj.masterid;
				valueObj.name = kdup.getJsonVal(row, "stockname", "");
				valueObj.number = kdup.getJsonVal(row, "stocknumber", "");
				valueObj.isopenlocation = kdup.getJsonVal(row, "isspmgr", "");
				array[i].rules.rowvalue = valueObj;
				array[i].rules.value = valueObj.name;
			}
		}
		//解锁库存状态
		else if (array[i].property.ffieldtype == 54) {
			if (row.isbarcodemgr == 0) {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁库存状态
			} else if (array[i].property.finorout == 1 || array[i].property.finorout == 2 || array[i].property.finorout == -1) {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁库存状态
			} else {
				array[i].rules.verify = "" //非必录
				array[i].disabled = true; //锁定库库存状态
			}
			var valueObj = {
				id: 0,
				number: "",
				name: "",
				masterid: 0

			};
			var stockId = kdup.getJsonVal(row, "stockstatusid", 0);
			if(array[i].savelastvalue != null && array[i].property.finorout==1 && array[i].property.fscanposition ==1
				&& !isedit && array[i].property.fisnosavelast!=1) {
			    array[i].rules.value = array[i].savelastvalue.displayVal;
				array[i].rules.rowvalue = array[i].savelastvalue.saveValue;
				}else if (stockId > 0) {
				valueObj.id = stockId;
				valueObj.masterid = kdup.getJsonVal(row, "stockstatusmasterid", 0);
				valueObj.masterid = valueObj.masterid == 0 ? stockId : valueObj.masterid;
				valueObj.name = kdup.getJsonVal(row, "stockstatusname", "");
				valueObj.number = kdup.getJsonVal(row, "stockstatusnumber", "");
				array[i].rules.rowvalue = valueObj;
				array[i].rules.value = valueObj.name;
			}
			
		}

		//解锁库位
		else if (array[i].property.ffieldtype == 8) {
			var stock = kdup.getJson(array, "key", kdup.mainFieleKey.stock.fkey)
			if (stock.rules.rowvalue.isopenlocation == 0) {
				array[i].rules.verify = "" //非必录
				array[i].disabled = true; //锁定库位
			} else if (row.isbarcodemgr == 0) {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁库位
			} else if (array[i].property.finorout == 1 || array[i].property.finorout == 2 || array[i].property.finorout == -1) {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁库位
			} else {
				array[i].rules.verify = "" //非必录
				array[i].disabled = true; //锁定库位
			}

			//这里调用接口取库位
			if (row.isspmgr == 1) {
				var valueObj = {
					id: 0,
					number: "",
					name: "",
					masterid: 0
				
				};
				var stockId = kdup.getJsonVal(row, "spid", 0);
				if(array[i].savelastvalue != null && array[i].property.finorout==1 && array[i].property.fscanposition ==1
					&& !isedit && array[i].property.fisnosavelast!=1) {
				    array[i].rules.value = array[i].savelastvalue.displayVal;
					array[i].rules.rowvalue = array[i].savelastvalue.saveValue;
					}else if (stockId > 0) {
					valueObj.id = stockId;
					valueObj.masterid = stockId;
					valueObj.name = kdup.getJsonVal(row, "spname", "");
					valueObj.number = kdup.getJsonVal(row, "spnumber", "");
					array[i].rules.rowvalue = valueObj;
					array[i].rules.value = valueObj.name;
				}
			} else {
				array[i].rules.value = "";
				array[i].rules.rowvalue.id = "";
			}
		}

		//解锁批号      //解锁转换后批次
		else if (array[i].property.ffieldtype == 9 ) {
			var valueObj = {
				id: 0,
				name: ""
			};
			if (row.isbatchmgr == 0) {
				array[i].rules.verify = "" //非必录
				array[i].disabled = true; //锁定批号
			} else if (row.isbarcodemgr == 0) {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁批号
			} else if (array[i].property.finorout == 1 || array[i].property.finorout == 2 || array[i].property.finorout == -1) {
				//入库是文本出库是选择
				//array[i].type = "number";
				//array[i].rules.flag = '999';
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁批号
			} else {
				array[i].rules.verify = "" //非必录
				array[i].disabled = true; //锁定批号
			}
			if (row.isbatchmgr == 1) {
				if(array[i].savelastvalue != null && array[i].property.finorout==1 && array[i].property.fscanposition ==1
					&& !isedit && array[i].property.fisnosavelast!=1) {
				    array[i].rules.value = array[i].savelastvalue.displayVal;
					array[i].rules.rowvalue = array[i].savelastvalue.saveValue;
					}else{
						valueObj.id = kdup.getJsonVal(row, "lotid", "");
						valueObj.name = kdup.getJsonVal(row, "lotnumber", "");
						array[i].rules.value = valueObj.name;
						array[i].rules.rowvalue = valueObj;
					}
			} else {
				array[i].rules.value = "";
				array[i].rules.rowvalue = {id:0,name:""};
			}
		}

		//解锁有效期
		else if (array[i].property.ffieldtype == 10) {
			if (row.iskfperiod == 0) {
				array[i].rules.verify = "" //非必录
				array[i].disabled = true; //锁定有效期
			} else if (row.isbarcodemgr == 0) {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁有效期
			} else if (array[i].property.finorout == 1 || array[i].property.finorout == 2 || array[i].property.finorout == -1) {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁有效期
			} else {
				array[i].rules.verify = "" //非必录
				array[i].disabled = true; //锁定有效期
			}
			if (row.iskfperiod == 1) {
				if(array[i].savelastvalue != null && array[i].property.finorout==1 && array[i].property.fscanposition ==1
					&& !isedit && array[i].property.fisnosavelast!=1) {
				    array[i].rules.value = array[i].savelastvalue.displayVal;
					array[i].rules.rowvalue = array[i].savelastvalue.saveValue;
					}else{//如果日期等于空或者不正确则默认当天日期
						var d = new Date();
						var ye = d.getFullYear();
						var mo = (d.getMonth()+1).toString().padStart(2,'0');
						var da = d.getDate().toString().padStart(2,'0');
						var time = ye+'-'+mo+'-'+da;
					    if(kdup.isEmpty(row.fproductdate) || row.fproductdate.substr(0, 1) == "0"){
						 array[i].rules.value = time;
						 array[i].rules.rowvalue.id =time;
					    }else{
							array[i].rules.value = row.fproductdate;
							array[i].rules.rowvalue.id = row.fproductdate;
						}
					}
			} else {
				array[i].rules.value = "";
				array[i].rules.rowvalue.id = "";
			}
		}

		//解锁数量   入库单据 1  出库单据-1 调拨单据0 非库存单据2
		else if (array[i].property.ffieldtype == 11) {
			if (array[i].property.finorout == 1 || array[i].property.finorout == 2 || array[i].property.finorout == -1) {
				if (row.barcodetype == 1) {
					array[i].rules.verify = "req" //必录
					array[i].disabled = true; //解锁数量  
					array[i].rules.value = parseFloat(row.printqty) //如果是入库就是打印数量
					array[i].rules.rowvalue.id = parseFloat(row.printqty)
				} else {
					array[i].rules.verify = "req" //必录
					array[i].disabled = false; //解锁数量  
					array[i].rules.value = parseFloat(row.printqty) //如果是入库就是打印数量
					array[i].rules.rowvalue.id = parseFloat(row.printqty)
				}
			} else {
				array[i].rules.verify = "req" //必录
				array[i].disabled = false; //解锁数量
				array[i].rules.value = parseFloat(row.printqty) //否则就是库存数量
				array[i].rules.rowvalue.id = parseFloat(row.printqty);
			}
		}
		
		//辅助属性赋值
		else if(auxProptyInfos != null && auxProptyInfos.length > 0){
			for(var j=0;j<auxProptyInfos.length;j++){
				if(array[i].key==auxProptyInfos[j].key){
					array[i].rules.rowvalue = auxProptyInfos[j];
					if(auxProptyInfos[j].hasOwnProperty("name"))
						array[i].rules.value = auxProptyInfos[j].name;
					else 
						array[i].rules.value = auxProptyInfos[j].id;
				}
			}
		}else if(array[i].property.ffieldtype == 81){
			array[i].disabled = true; 
		}else if(array[i].property.ffieldtype == 14){//复选框赠品
			array[i].rules.value = array[i].property.fnullvalue;
			array[i].rules.rowvalue.id = array[i].property.fnullvalue;
			array[i].disabled = false; //解锁
			
		}
		//生产订单编号
		// else if(array[i].property.ffieldtype == 17){
		// 	array[i].rules.verify = "" //非必录
		// 	array[i].disabled = true; 
		// }
		else{
			array[i].disabled = false; //解锁
		}
	}
	return array;
} 
//选择仓库从新赋值
kdup.stockSetValue = function(array, data, that, fieldType) {
	if(fieldType == 71) return;
	var row=data.Table[0];
	var auxProptyInfos = null;
	if(data.hasOwnProperty("auxProptyInfos"))
		auxProptyInfos = data.auxProptyInfos;
	for (var i = 0; i < array.length; i++) {
		//解锁库存状态
		if (array[i].property.ffieldtype == 54) {
			var valueObj = {
				id: 0,
				number: "",
				name: "",
				masterid: 0
			};
			var stockId = kdup.getJsonVal(row, "stockstatusid", 0);
			if (stockId > 0) {
				valueObj.id = stockId;
				valueObj.masterid = kdup.getJsonVal(row, "stockstatusmasterid", 0);
				valueObj.masterid = valueObj.masterid == 0 ? stockId : valueObj.masterid;
				valueObj.name = kdup.getJsonVal(row, "stockstatusname", "");
				valueObj.number = kdup.getJsonVal(row, "stockstatusnumber", "");
			}
			array[i].rules.rowvalue = valueObj;
			array[i].rules.value = valueObj.name;
		}

		//解锁库位
		else if (array[i].property.ffieldtype == 8) {
			//这里调用接口取库位
			if (row.isspmgr == 1) {
				var valueObj = {
					id: 0,
					number: "",
					name: "",
					masterid: 0
				
				};
				var stockId = kdup.getJsonVal(row, "spid", 0);
				if (stockId > 0) {
					valueObj.id = stockId;
					valueObj.masterid = stockId;
					valueObj.name = kdup.getJsonVal(row, "spname", "");
					valueObj.number = kdup.getJsonVal(row, "spnumber", "");
				}
				array[i].rules.rowvalue = valueObj;
				array[i].rules.value = valueObj.name;

			} else {
				array[i].rules.value = "";
				array[i].rules.rowvalue.id = "";
			}
		}

		//解锁批号
		else if (array[i].property.ffieldtype == 9) {
			var valueObj = {
				id: 0,
				name: ""
			};
			if (row.isbatchmgr == 1) {
				valueObj.id = kdup.getJsonVal(row, "lotid", "");
				valueObj.name = kdup.getJsonVal(row, "lotnumber", "");
				array[i].rules.value = valueObj.name;
				array[i].rules.rowvalue = valueObj;
			} else {
				array[i].rules.value = "";
				array[i].rules.rowvalue = {id:0,name:""};
			}
		}

		//解锁有效期
		else if (array[i].property.ffieldtype == 10) {
			if (row.iskfperiod == 1) {
				array[i].rules.value = row.fproductdate;
				array[i].rules.rowvalue.id = row.fproductdate;
			} else {
				array[i].rules.value = "";
				array[i].rules.rowvalue.id = "";
			}
		}

		//解锁数量
		else if (array[i].property.ffieldtype == 11) {
			array[i].rules.value = parseFloat(row.invqty) //否则就是库存数量
			array[i].rules.rowvalue.id = parseFloat(row.invqty);
		}else if(auxProptyInfos != null && auxProptyInfos.length > 0){
		//辅助属性赋值
			for(var j=0;j<auxProptyInfos.length;j++){
				if(array[i].key==auxProptyInfos[j].key){
					array[i].rules.rowvalue = auxProptyInfos[j];
					if(auxProptyInfos[j].hasOwnProperty("name"))
					array[i].rules.value = auxProptyInfos[j].name;
					else 
					array[i].rules.value = auxProptyInfos[j].id;
				}
			}
		}
	}
	return array;
}
//选择仓库解锁库位
kdup.openlocation = function(array, stockObj, that, fieldType) {
	var valueObj = {id: 0, name: ""};
	var spFieldType = 0;
	if(fieldType == 7) spFieldType = 8;
	else if(fieldType == 71) spFieldType = 81;
	else return;
	
	for (var i = 0; i < array.length; i++) {
		if (kdup.isEmpty(array[i].key) || array[i].property.ffieldtype != spFieldType) 
			continue;
		if (stockObj.isopenlocation != 0) {
			array[i].rules.verify = "req" //必录
			array[i].disabled = false; //解锁库位
			array[i].rules.value = ""; 
			array[i].rules.rowvalue = {
				id: 0, name:""
			};
		} else {
			array[i].disabled = true; //锁定库位
			array[i].rules.value = ""; 
			array[i].rules.verify = "" //非必录
			array[i].rules.rowvalue = {
				id: 0, name:""
			};
		}
	}
	return array;
}
//解析拼接过滤条件
kdup.getFilter = function(jsonArray, filter) {

	if (!kdup.isEmpty(filter)) {
		//解析sql语句
		var str = filter;
		while (str.indexOf("{#") > -1) {
			var index = str.indexOf("{#");
			var index1 = str.indexOf("#}");
			var key = str.substring(index + 2, index1);
			var obj = kdup.getJson(jsonArray, "key", key);
			var value = obj.rules.rowvalue.id;
			if (kdup.isEmpty(value) || value == "0") {
				uni.showToast({
					title: "请先输入" + obj.property.ftitle,
					icon: "none",
					duration: 3000,
				});
				return;
			}
			filter = filter.replace("{#" + key + "#}", value);
			str = str.substring(index1 + 2, str.length);
		}
	}
	return filter;

};
//放回sql语句
kdup.getEntryBarcodeSql = function(id,num,formDate) {
	//条码信息的
	var stockNameAs = "仓库", spNameAs = "库位", toSelect = "", toFrom = "";
	if(kdup.config.finorout == 0){
		stockNameAs = "调出仓库";
		spNameAs = "调出库位";
		toSelect = ",ds2.FName 调入仓库,u1.FSPIDTO_Name 调入库位";
		toFrom = " left join t_bd_stock_l ds2 on u1.FStockTo = ds2.FStockId and ds2.FLOCALEID = 2052 ";
	}
	var sql ="";
	if(num==1){
		//条码信息列表
		 sql = "/*dialect*/select v1.FNUMBER FBarcode ,m1.FNUMBER fmatnumber ,m2.FName fmatname,m2.FSPECIFICATION ," +
			"n1.FNAME 单位 ,cast(u1.FQty as float) fqty,s2.FNAME "+stockNameAs+",u1.fspid_name "+spNameAs+ toSelect + ",u1.flot_text ," +
			"convert(varchar(20),u1.FPRODUCTDATE,23) 生产日期,'' auxpropname,case when v1.FISONLY = 1 then '是' else '否' end 是否唯一码,"+
			"case when v1.FBarcodeType='1' then '包装条码' else '小包条码' end 条码类型," +
			"u1.FEntryID entyid,u1.FQty fqty_hide, u1.FAUXPROPID auxpropid_hide,m1.FMaterialId materialId_hide" +
			" from top_TerminalDataEntry u1 inner join t_bbb_barcode v1 on u1.FBarcode = v1.fid  " +
			"inner join t_bd_material m1 on v1.FMATERIALID = m1.FMaterialId " +
			"	inner join T_BD_MATERIAL_L m2 on m2.FMATERIALID = m1.FMATERIALID and m2.FLOCALEID = 2052" +
			"	inner join T_BD_UNIT_L n1 on n1.FUNITID = v1.FUNITID and n1.FLOCALEID = 2052	" +
			"left join t_bd_stock s1 on s1.FStockId = u1.FStockId	" +
			"left join t_bd_stock_l s2 on s1.FStockId = s2.FStockId and s2.FLOCALEID = 2052 " + toFrom + 
			" where u1.FID = '" + id + "' order by u1.fentryid ";
	}else if(num==2){//工序信息列表
	var key = kdup.getJson(formDate, "key", "FCZY");
	key=key.rules.value.replace(/,/g,";");
		sql = "/*dialect*/select gxl.FNAME 工序,Convert(decimal(18,2),gx.FGXQTY)  汇报数量,Convert(decimal(18,2),gx.FFAILQTY) 不合格数, " +
		" Convert(decimal(18,2),gx.FBADQTY)报废数量,CONVERT(varchar(100),gx.fdatetime, 20) 汇报时间, " +
		" src.FSRCBILLNO +'-'+cast(src.FSRCENTRYSEQ as varchar(20)) 对应生产订单,'"+key+"' 操作员,jt.FNAME 机台编号,case  when gx.FDUTYWORK2='A' then '白班'  else '夜班' end  排班,bhg.FNAME 不合格原因,bf.FNAME 报废原因,gx.FEntryID entyid " +
		" from  top_TerminalDataEntry_Gx gx inner join top_t_GXXL_L gxl on gx.FGXXL1=gxl.FID " +
		" inner join top_TerminalDataEntry_Src src on src.FID=gx.fid  and src.FSRCENTRYID=gx.FSRCNO  " +
		" left join top_t_BHGREASON_l bhg on bhg.FID=gx.FBHGYY1 left join top_t_BFREASON_l bf on bf.FID=gx.FBFYY1 " +
		" inner join KDUP_t_JTSJ_L jt on gx.FJTID2=jt.fid where gx.fid='" + id + "'";
	}else if(num==3){//工序源单信息列表
		sql="/*dialect*/select src.FSRCBILLNO +'-'+cast(src.FSRCENTRYSEQ as varchar(20)) 生产订单号," +
		" mr.FNUMBER,mrl.FNAME fmatname,mrl.FSPECIFICATION,Convert(decimal(18,2),src.FSRCQTY) fqty,src.FEntryID entyid from top_TerminalDataEntry_Src src " +
		" inner join T_BD_MATERIAL mr on mr.FMATERIALID=src.FSRCMATERIALID inner join T_BD_MATERIAL_L mrl " +
		" on mr.FMATERIALID=mrl.FMATERIALID where src.fid='"+id+"'";
	}else if(num==4){//所有临时表
		sql="/*dialect*/select e.FNAME 创建人,b.FNAME 单据类型,CONVERT (CHAR(20), FMODIFYDATE, 120) 创建时间,b.fid 单据内码,s.fid id  from top_TerminalData s inner join t_sec_user e on e.FUSERID=s.FCREATORID "+
            " inner join  top_barcode_config_L  b on b.FID=s.FBARCODEBILLTYPE order by e.FNAME";
	}else if(num==5){//所有配置表
	 sql="/*dialect*/select c.FNAME fname, CASE FINOROUT WHEN '1' THEN '入库' WHEN '-1' THEN '出库' WHEN '0' THEN '调拨' ELSE '非库存单据' END 出入库,b.FBILLTYPETEXT 单据业务类型,b.fid id   from top_barcode_config  b inner "+
	            "  join top_barcode_config_L c on b.FID=c.FID where FFORBIDSTATUS='A'";
	}
	return sql;
};

//显示/隐藏的辅助属性
kdup.hideAuxproperty = function(showauxproptykeys, allauxproptykeys, formatDate) {
	//显示的辅助属性
	var showaux = showauxproptykeys + ",";
	//全部的辅助属性
	var allaux = allauxproptykeys + ",";
	for (var k = 0; k < formatDate.length; k++) {
		if (kdup.isEmpty(formatDate[k].key)) continue;
		var key = formatDate[k].key + ",";
		if (showaux.indexOf(key) > -1) {
			formatDate[k].property.fishidden = 0;
			//formatDate[k].disabled = false;
			formatDate[k].disabled = true;//更改为始终锁定
		} else if (allaux.indexOf(key) > -1) {
			formatDate[k].property.fishidden = 1;
		}
	}
	return formatDate;
};
//解锁库存属性
kdup.unLockAuxproperty = function(aux, formatDate) {
	var showaux = aux.split(",")
	for (var i = 0; i < showaux.length; i++) {
		for (var j = 0; j < formatDate.length; j++) {
			if (showaux[i] == formatDate[j].key) {
				formatDate[j].disabled = true;
			}
		}
	}
	return formatDate;
};
//判断类型放回控件
kdup.istype = function(data) {
	//类型处理
	if (data == 1 || data == 10) {
		return "date"
	} else if (data == 2 || data == 3 || data == 11) {
		return "number"
	} else if (data == 15 || data == 16) {
		return "radio"
	}else if (data == 14) {
		return "checkbox"
	} else {
		return "text"
	}
	};

export default kdup
